package com.keyin;

import com.keyin.android.view.ChangeFocusListener;
import com.keyin.android.view.SegmentControl;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

public class Web extends BaseActivity{

	private WebView webView;
	private ProgressDialog progressDialog;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.a_web);
		
		webView = (WebView)findViewById(R.id.webview);
		webView.loadUrl("http://3g.keyin.cn");
		
		webView.getSettings().setJavaScriptEnabled(true);
		
		webView.setWebChromeClient(new WebChromeClient(){
			public void onProgressChanged(WebView view, int progress) {
				if(progress == 100) {
					progressDialog.dismiss();
				}
			}
		});
		
		progressDialog = ProgressDialog.show(this, "请稍候", "正在获取数据", true);
		progressDialog.setCancelable(true); 
		progressDialog.setProgressStyle(android.R.style.Theme_Translucent);
		progressDialog.setOnCancelListener(new OnCancelListener() {
			@Override
			public void onCancel(DialogInterface d) {
			}
		});
		
		SegmentControl segment = (SegmentControl) findViewById(R.id.segment_control);
		segment.setChangeFocusListener(new ChangeFocusListener() {

			@Override
			public void onFocus(View v, int position) {

				Intent i = new Intent();
				i.setClass(Web.this, Main.class);
				i.putExtra(Main.MAIN_INDEX_KEY, position);
				i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				startActivity(i);
				
				finish();
			}

			@Override
			public void onBlur(View v, int position) {
			}
		});
	}
}
